{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ffea3a4a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import potentials\n",
    "import atomman as am\n",
    "import iprPy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1da8b737",
   "metadata": {},
   "source": [
    "## Load the database\n",
    "\n",
    "The database to use where the calculation records will be added to and to search for existing calculations to skip."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3a074418",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "database style local at E:\\calculations\\ipr\\test\n"
     ]
    }
   ],
   "source": [
    "database = iprPy.load_database('test')\n",
    "print(database)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "04ee5f35",
   "metadata": {},
   "source": [
    "## Required terms\n",
    "\n",
    "These are the basic terms required by most calculations in the workflow\n",
    "\n",
    "- __lammps_command__ is the primary LAMMPS executable to use.\n",
    "- __mpi_command__ is the MPI command to use.  Leave {np_per_runner} as a variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "54611e18",
   "metadata": {},
   "outputs": [],
   "source": [
    "prepare_terms = {}\n",
    "prepare_terms['lammps_command'] = 'lmp_mpi'\n",
    "prepare_terms['mpi_command'] = 'C:/Program Files/MPICH2/bin/mpiexec -localonly {np_per_runner}'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "baa80b77",
   "metadata": {},
   "source": [
    "## Optional: Alternate LAMMPS executables\n",
    "\n",
    "These are alternate LAMMPS executables to use with interatomic potentials that are not compatible with the primary executable set above.  \n",
    "- __lammps_command_snap_1__ asdf\n",
    "- __lammps_command_snap_1__ asdf\n",
    "- __lammps_command_old__ asdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ba99926b",
   "metadata": {},
   "outputs": [],
   "source": [
    "#prepare_terms['lammps_command_snap_1'] = 'C:/Program Files/LAMMPS/2017-01-27/bin/lmp_mpi'\n",
    "#prepare_terms['lammps_command_snap_2'] = 'C:/Program Files/LAMMPS/2019-06-05/bin/lmp_mpi'\n",
    "#prepare_terms['lammps_command_old'] = 'C:/Program Files/LAMMPS/2019-06-05/bin/lmp_mpi'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "40505cf0",
   "metadata": {},
   "source": [
    "## Optional: Potential limiters\n",
    "\n",
    "Any term keys that start with \"potential_\" are passed into get_lammps_potential() as kwargs (without the potential_ prefix) allowing for parsing of the potentials which will be used for preparing the calculations.\n",
    "\n",
    "Examples used here:\n",
    "- __potential_status__ limits the included potential version status.  Values are all, active, superseded or retracted. Default value is active, which is best for most users as it only includes the newest versions of the available potentials.\n",
    "- __potential_id__ limits the potentials used to only the ones explicitly listed by id.\n",
    "- __potential_pair_style__ limits the potentials used to only the ones with a LAMMPS pair_style included in the list."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8a40ac88",
   "metadata": {},
   "outputs": [],
   "source": [
    "#prepare_terms['potential_status'] = 'all'\n",
    "\n",
    "prepare_terms['potential_id'] = [\n",
    "    '1999--Mishin-Y--Al--LAMMPS--ipr1',\n",
    "    #'EAM_CubicNaturalSpline_ErcolessiAdams_1994_Al__MO_800509458712_002',\n",
    "]\n",
    "\n",
    "#prepare_terms['potential_pair_style'] = [\n",
    "#    'eam', 'eam/alloy', 'eam/fs', 'eam/cd',\n",
    "#]     "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f83d2d7",
   "metadata": {},
   "source": [
    "## Calculation Pools\n",
    "\n",
    "The prepared calculations are divided into separate \"pools\" where the prepared calculations will be executed from.  \n",
    "\n",
    "By default, the iprPy runner methods are all assigned a set number of processors to work with, and then runs through the calculations in a pool by randomly selecting them. As such, individual pools should be used for different steps along the workflow, as well as for calculations that will be assigned different numbers of processors.\n",
    "\n",
    "Each pool is defined with the following master prepare parameters\n",
    "- __styles__ lists the iprPy calculation styles to prepare in the pool.  By default, these will use the pre-defined \"main\" branch, but alternate branches can be selected by giving the branch name after a :.\n",
    "- __run_directory__ is the name of the specific run directory where the pool is located.  All prepared calculations will be created in this run directory.\n",
    "- __np_per_runner__ is the number of processors each runner will be assigned to use for the underlying simulations.\n",
    "\n",
    "__NOTE:__ These values can either be singular or lists of equal length.  Giving list values allows for multiple pools to be prepared with the same master_prepare call.  This Notebook updates the values and only builds one pool at a time for more interactivity."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3a8e5fe",
   "metadata": {},
   "source": [
    "### Pool #1: Basic potential evaluations and scans\n",
    "\n",
    "Styles\n",
    "\n",
    "- __isolated_atom__ evaluates the energy of a single atom in isolation.\n",
    "- __diatom_scan__ evaluates the energy of a pair of atoms at various interatomic spacings.\n",
    "- __E_vs_r_scan__ evaluates the energy of crystal prototypes subjected to a volumetric scan.\n",
    "- __E_vs_r_scan:bop__ evaluates the energy of crystal prototypes subjected to a volumetric scan. Uses a higher rmin to avoid extremely costly energy evaluations for bop potentials."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2e2d03cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation isolated_atom branch main\n",
      "1 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "1 calculation combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Preparing calculation diatom_scan branch main\n",
      "1 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "1 calculation combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Preparing calculation E_vs_r_scan branch main\n",
      "10 existing calculation records found\n",
      "19 matching crystal prototypes found\n",
      "1 matching interatomic potentials found\n",
      "10 calculation combinations to check\n",
      "0 new records to prepare\n",
      "\n",
      "Preparing calculation E_vs_r_scan branch bop\n",
      "10 existing calculation records found\n",
      "19 matching crystal prototypes found\n",
      "0 matching interatomic potentials found\n",
      "1 invalid calculations skipped\n",
      "0 calculation combinations to check\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    'isolated_atom',\n",
    "    'diatom_scan',\n",
    "    'E_vs_r_scan',\n",
    "    'E_vs_r_scan:bop',\n",
    "]\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_1'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc6b9c5e",
   "metadata": {},
   "source": [
    "### Pool #2: Round 1 of crystal structure relaxations\n",
    "\n",
    "Styles\n",
    "\n",
    "- __relax_box__ relaxes a structure by only adjusting the box dimensions and not the atom positions.\n",
    "- __relax_static__ relaxes a structure using energy/force minimizations. \n",
    "- __relax_dynamic__ relaxes a structure using dynamic Langevin energy damping, with only a single \"kick\" at the beginning."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "a3c2370e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation relax_box branch main\n",
      "0 existing calculation records found\n",
      "6587 matching atomic references found\n",
      "1 matching interatomic potentials found\n",
      "1 matching interatomic potentials found\n",
      "10 matching atomic parents found\n",
      "39 calculation combinations to check\n",
      "39 new records to prepare\n",
      "\n",
      "Preparing calculation relax_static branch main\n",
      "0 existing calculation records found\n",
      "6587 matching atomic references found\n",
      "1 matching interatomic potentials found\n",
      "1 matching interatomic potentials found\n",
      "10 matching atomic parents found\n",
      "39 calculation combinations to check\n",
      "39 new records to prepare\n",
      "\n",
      "Preparing calculation relax_dynamic branch main\n",
      "0 existing calculation records found\n",
      "6587 matching atomic references found\n",
      "1 matching interatomic potentials found\n",
      "1 matching interatomic potentials found\n",
      "10 matching atomic parents found\n",
      "39 calculation combinations to check\n",
      "39 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    'relax_box',\n",
    "    'relax_static',\n",
    "    'relax_dynamic',\n",
    "]\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_2'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a86e88a",
   "metadata": {},
   "source": [
    "### Pool #3: Round 2 of crystal structure relaxations\n",
    "\n",
    "Styles\n",
    "\n",
    "- __relax_static:from_dymanic__ further relaxes the results of the relax_dynamic calculation above using the relax_static method. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c48c433d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation relax_static branch from_dynamic\n",
      "39 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "39 matching atomic archives found\n",
      "39 calculation combinations to check\n",
      "39 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    'relax_static:from_dynamic'\n",
    "]\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_3'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "34367006",
   "metadata": {},
   "source": [
    "### Pool #4: Crystal space group analysis\n",
    "\n",
    "Styles\n",
    "\n",
    "- __crystal_space_group:prototype__ performs a space group analysis on the prototype reference structures in the database.\n",
    "- __crystal_space_group:reference__ performs a space group analysis on any DFT reference structures in the database.\n",
    "- __crystal_space_group:relax__ performs a space group analysis on all of the results of the relax_box, relax_static and relax_static:from dynamic calculations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "2ece04c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation crystal_space_group branch relax\n",
      "88 existing calculation records found\n",
      "59 matching atomic archives found\n",
      "29 matching atomic archives found\n",
      "88 calculation combinations to check\n",
      "0 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    #'crystal_space_group:prototype',\n",
    "    #'crystal_space_group:reference',\n",
    "    'crystal_space_group:relax',\n",
    "]\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_4'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ebc78e6",
   "metadata": {},
   "source": [
    "- - -\n",
    "\n",
    "### NOTE: \n",
    "\n",
    "All pools after this point use relaxed_crystal structures as the structure inputs.  These are generated from the relaxed structures and the associated crystal space group calculations using the !(process-relaxed method)!"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "dc644860",
   "metadata": {},
   "source": [
    "### Pool #5: Elastic constants and phonons\n",
    "\n",
    "Styles\n",
    "\n",
    "- __elastic_constants_static__ computes the static elastic constants of a crystal structure using small strains.\n",
    "- __phonon__ uses phonopy to evaluate the phonons of a crystal structure and performs a quasiharmonic analysis if possible."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "79a6b651",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation elastic_constants_static branch main\n",
      "0 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "10 matching atomic parents found\n",
      "30 calculation combinations to check\n",
      "30 new records to prepare\n",
      "\n",
      "Preparing calculation phonon branch main\n",
      "0 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "10 matching atomic parents found\n",
      "10 calculation combinations to check\n",
      "10 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    'elastic_constants_static',\n",
    "    'phonon',\n",
    "]\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_5'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b8de22cf",
   "metadata": {},
   "source": [
    "### Pool #6: Simple crystal defects\n",
    "\n",
    "__NOTE__: While these styles can be prepared similarly to the others, it is much faster to pre-select the parent relaxed_crystal records based on their associated prototypes.  Therefore, this code calls master_prepare separately for each style+family combination.\n",
    "\n",
    "\n",
    "Styles\n",
    "- __point_defect_static__ computes point defect formation energies and elastic dipole tensors.\n",
    "- __surface_energy_static__ computes free surface formation energies.\n",
    "- __stacking_fault_map_2D__ computes 2D stacking fault energy maps a.k.a. gamma surfaces.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1167abb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "styles = [\n",
    "    'point_defect_static',\n",
    "    'surface_energy_static',\n",
    "    'stacking_fault_map_2D',\n",
    "]\n",
    "\n",
    "prepare_terms['run_directory'] = 'master_6'\n",
    "prepare_terms['np_per_runner'] = '1'\n",
    "\n",
    "for style in styles:\n",
    "    print(style)\n",
    "    prepare_terms['styles'] = style\n",
    "    \n",
    "    # Get defect reference records\n",
    "    if style == 'point_defect_static':\n",
    "        defects = database.get_records_df(style='point_defect')\n",
    "    elif style == 'surface_energy_static':\n",
    "        defects = database.get_records_df(style='free_surface')\n",
    "    elif style == 'stacking_fault_map_2D':\n",
    "        defects = database.get_records_df(style='stacking_fault')\n",
    "    \n",
    "    # Loop over reference record family values\n",
    "    for family in np.unique(defects.family):\n",
    "        print(family)\n",
    "        prepare_terms['parent_family'] = family\n",
    "        prepare_terms['defect_family'] = family\n",
    "        database.master_prepare(**prepare_terms)\n",
    "\n",
    "del prepare_terms['parent_family']\n",
    "del prepare_terms['defect_family']"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "182b2dde",
   "metadata": {},
   "source": [
    "### Pool #7: Dislocation core constructions\n",
    "\n",
    "Styles\n",
    "\n",
    "- __dislocation_monopole:fcc_edge_100__ builds a dislocation monopole system for an fcc edge dislocation on a (100) plane.\n",
    "- __dislocation_monopole:bcc_screw__ builds a dislocation monopole system for a bcc screw dislocation on a (110) plane.\n",
    "- __dislocation_monopole:bcc_edge__ builds a dislocation monopole system for a bcc edge dislocation on a (110) plane.\n",
    "- __dislocation_monopole:bcc_edge_112__ builds a dislocation monopole system for a bcc edge dislocation on a (112) plane.\n",
    "- __dislocation_periodic_array:fcc_edge_mix__ builds a periodic array of dislocations system for an fcc edge or mixed dislocation on a (111) plane.\n",
    "- __dislocation_periodic_array:fcc_screw__ builds a periodic array of dislocations system for an fcc screw dislocation on a (111) plane."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c76f5116",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Preparing calculation dislocation_monopole branch fcc_edge_100\n",
      "1 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "1 matching atomic archives found\n",
      "1 matching defects\n",
      "1 calculation combinations to check\n",
      "1 new records to prepare\n",
      "\n",
      "Preparing calculation dislocation_monopole branch bcc_screw\n",
      "2 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "0 matching atomic archives found\n",
      "1 matching defects\n",
      "1 invalid calculations skipped\n",
      "0 calculation combinations to check\n",
      "\n",
      "Preparing calculation dislocation_monopole branch bcc_edge\n",
      "2 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "0 matching atomic archives found\n",
      "1 matching defects\n",
      "1 invalid calculations skipped\n",
      "0 calculation combinations to check\n",
      "\n",
      "Preparing calculation dislocation_monopole branch bcc_edge_112\n",
      "2 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "0 matching atomic archives found\n",
      "1 matching defects\n",
      "1 invalid calculations skipped\n",
      "0 calculation combinations to check\n",
      "\n",
      "Preparing calculation dislocation_periodic_array branch fcc_edge_mix\n",
      "0 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "1 matching atomic archives found\n",
      "1 matching defects\n",
      "1 calculation combinations to check\n",
      "1 new records to prepare\n",
      "\n",
      "Preparing calculation dislocation_periodic_array branch fcc_screw\n",
      "1 existing calculation records found\n",
      "1 matching interatomic potentials found\n",
      "1 matching atomic archives found\n",
      "1 matching defects\n",
      "1 calculation combinations to check\n",
      "1 new records to prepare\n",
      "\n"
     ]
    }
   ],
   "source": [
    "styles = [\n",
    "    'dislocation_monopole:fcc_edge_100',\n",
    "    'dislocation_monopole:bcc_screw',\n",
    "    'dislocation_monopole:bcc_edge',\n",
    "    'dislocation_monopole:bcc_edge_112',\n",
    "    'dislocation_periodic_array:fcc_edge_mix',\n",
    "    'dislocation_periodic_array:fcc_screw',\n",
    "]\n",
    "\n",
    "prepare_terms['styles']        = ' '.join(styles)\n",
    "prepare_terms['run_directory'] = 'master_7'\n",
    "prepare_terms['np_per_runner'] = '8'\n",
    "prepare_terms['annealsteps'] = '100000'\n",
    "database.master_prepare(**prepare_terms)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2475713d",
   "metadata": {},
   "source": [
    "### Pool #8: Temperature-dependent crystal relaxations\n",
    "\n",
    "Styles\n",
    "\n",
    "- __relax_dynamic:at_temp__ \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6c0c7097",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b757a8f4",
   "metadata": {},
   "source": [
    "## Database management methods"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9c63754a",
   "metadata": {},
   "source": [
    "### Check record statuses"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8f4c9005",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 1 of style calculation_diatom_scan\n",
      " - 1 finished\n",
      " - 0 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 1 of style calculation_isolated_atom\n",
      " - 1 finished\n",
      " - 0 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 10 of style calculation_E_vs_r_scan\n",
      " - 10 finished\n",
      " - 0 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 39 of style calculation_relax_box\n",
      " - 29 finished\n",
      " - 0 not finished\n",
      " - 10 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 78 of style calculation_relax_static\n",
      " - 60 finished\n",
      " - 0 not finished\n",
      " - 18 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 39 of style calculation_relax_dynamic\n",
      " - 39 finished\n",
      " - 0 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 88 of style calculation_crystal_space_group\n",
      " - 88 finished\n",
      " - 0 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 30 of style calculation_elastic_constants_static\n",
      " - 27 finished\n",
      " - 0 not finished\n",
      " - 3 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 10 of style calculation_phonon\n",
      " - 6 finished\n",
      " - 2 not finished\n",
      " - 2 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 19 of style calculation_point_defect_static\n",
      " - 0 finished\n",
      " - 4 not finished\n",
      " - 15 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 65 of style calculation_surface_energy_static\n",
      " - 45 finished\n",
      " - 20 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 48 of style calculation_stacking_fault_map_2D\n",
      " - 27 finished\n",
      " - 21 not finished\n",
      " - 0 issued errors\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 0 of style calculation_dislocation_monopole\n",
      "In database style local at E:\\calculations\\ipr\\test:\n",
      "- 0 of style calculation_dislocation_periodic_array\n"
     ]
    }
   ],
   "source": [
    "for style in [\n",
    "    'diatom_scan',\n",
    "    'isolated_atom',\n",
    "    'E_vs_r_scan',\n",
    "    'relax_box',\n",
    "    'relax_static',\n",
    "    'relax_dynamic',\n",
    "    'crystal_space_group',\n",
    "    'elastic_constants_static',\n",
    "    'phonon',\n",
    "    'point_defect_static',\n",
    "    'surface_energy_static',\n",
    "    'stacking_fault_map_2D',\n",
    "    'dislocation_monopole',\n",
    "    'dislocation_periodic_array',\n",
    "    \n",
    "]:\n",
    "    database.check_records(f'calculation_{style}')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "49e95d78",
   "metadata": {},
   "source": [
    "### Delete all records"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "606aa1e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n",
      "0 records found to be destroyed\n"
     ]
    }
   ],
   "source": [
    "for style in [\n",
    "    'diatom_scan',\n",
    "    'isolated_atom',\n",
    "    'E_vs_r_scan',\n",
    "    'relax_box',\n",
    "    'relax_static',\n",
    "    'relax_dynamic',\n",
    "    'crystal_space_group',\n",
    "    'elastic_constants_static',\n",
    "    'phonon',\n",
    "    'point_defect_static',\n",
    "    'surface_energy_static',\n",
    "    'stacking_fault_map_2D',\n",
    "    'dislocation_monopole',\n",
    "    'dislocation_periodic_array',\n",
    "    \n",
    "]:\n",
    "    database.destroy_records(f'calculation_{style}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "661d5c89",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 records to clean\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'NoneType' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_22444/1895674783.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     16\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     17\u001b[0m ]:\n\u001b[1;32m---> 18\u001b[1;33m     \u001b[0mdatabase\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclean_records\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrecord_style\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34mf'calculation_{style}'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrun_directory\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'master_7'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32me:\\python-packages\\iprpy\\iprPy\\database\\IprPyDatabase.py\u001b[0m in \u001b[0;36mclean_records\u001b[1;34m(self, run_directory, record_style, records)\u001b[0m\n\u001b[0;32m    117\u001b[0m             \u001b[1;31m# Clean record and update in the database\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    118\u001b[0m             \u001b[0mrecord\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mclean\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 119\u001b[1;33m             \u001b[0mrecord\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    120\u001b[0m             \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate_record\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrecord\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mrecord\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    121\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32me:\\python-packages\\iprpy\\iprPy\\calculation\\dislocation_monopole\\DislocationMonopole.py\u001b[0m in \u001b[0;36mbuild_model\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    519\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpotential\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mafter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'calculation'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    520\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msystem\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mafter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'potential-LAMMPS'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 521\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdefect\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mafter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'system-info'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    522\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mminimize\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    523\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0melastic\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_model\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcalc\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32me:\\python-packages\\iprpy\\iprPy\\calculation_subset\\Dislocation.py\u001b[0m in \u001b[0;36mbuild_model\u001b[1;34m(self, model, **kwargs)\u001b[0m\n\u001b[0;32m    709\u001b[0m         \u001b[0mdisl\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'calculation-parameter'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcp\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mDM\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    710\u001b[0m         \u001b[0mcp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'slip_hkl'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf'{self.slip_hkl[0]} {self.slip_hkl[1]} {self.slip_hkl[2]}'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 711\u001b[1;33m         \u001b[0mcp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'ξ_uvw'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf'{self.ξ_uvw[0]} {self.ξ_uvw[1]} {self.ξ_uvw[2]}'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    712\u001b[0m         \u001b[0mcp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'burgers'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf'{self.burgers[0]} {self.burgers[1]} {self.burgers[2]}'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    713\u001b[0m         \u001b[0mcp\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'm'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34mf'{self.m[0]} {self.m[1]} {self.m[2]}'\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'NoneType' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "for style in [\n",
    "   # 'diatom_scan',\n",
    "   # 'isolated_atom',\n",
    "   # 'E_vs_r_scan',\n",
    "   # 'relax_box',\n",
    "   # 'relax_static',\n",
    "   # 'relax_dynamic',\n",
    "   # 'crystal_space_group',\n",
    "   # 'elastic_constants_static',\n",
    "   # 'phonon',\n",
    "   # 'point_defect_static',\n",
    "   # 'surface_energy_static',\n",
    "   # 'stacking_fault_map_2D',\n",
    "    'dislocation_monopole',\n",
    "    #'dislocation_periodic_array',\n",
    "    \n",
    "]:\n",
    "    database.clean_records(record_style=f'calculation_{style}', run_directory='master_7')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2404eda8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
